from django.contrib import admin
from course.models import CourseDirectionModel,CourseCategoryModel,CourseModel,TeacherModel,DiscountModel,DiscountTypeModel,ActivateModel,CourseActivateModel
# Register your models here.

# 注册模型类
# 自定义管理页面

# 自定义外键关联模型类，
# admin.TabularInline 让外键对应的数据  横向排列
# admin.StackedInline 让外键对饮高德数据，垂直纵向排列


class CourseCategoryInLine(admin.TabularInline):
    model = CourseCategoryModel
    fields = ['id','name','orders']

class CourseDirectionModelAdmin(admin.ModelAdmin):
    list_display = ['id','name']
    inlines = [CourseCategoryInLine]
# admin.site.register(CourseDirectionModel)
admin.site.register(CourseDirectionModel,CourseDirectionModelAdmin)


class CoruseCategoryModelAdmin(admin.ModelAdmin):
    list_display = ['id','name']
admin.site.register(CourseCategoryModel,CoruseCategoryModelAdmin)


class CoruseModelAdmin(admin.ModelAdmin):
    list_display = ['id','name','price','direction','category','teacher','course_cover_small']
    ordering = ['id']
    search_fields = ['name']
    list_filter = ['recomment_home_hot','recomment_home_top']
admin.site.register(CourseModel,CoruseModelAdmin)

class CoruseTeacherModelAdmin(admin.ModelAdmin):
    list_display = ['id','name','avatar_small']
admin.site.register(TeacherModel,CoruseTeacherModelAdmin)

# 活动
class ActivateModelAdmin(admin.ModelAdmin):
    list_display = ['id','name','start_time','end_time','description']
admin.site.register(ActivateModel,ActivateModelAdmin)

# 折扣类型  优惠类型
class DiscountTypeModelAdmin(admin.ModelAdmin):
    list_display = ['id','name','remark']
admin.site.register(DiscountTypeModel,DiscountTypeModelAdmin)

# 折扣表,优惠公式比啊
class DiscountModelAdmin(admin.ModelAdmin):
    list_display = ['id','name','discount_type','condition','sale']
admin.site.register(DiscountModel,DiscountModelAdmin)

class CourseActivateModelAdmin(admin.ModelAdmin):
    list_display = ['id','name','activate','course','discount']
admin.site.register(CourseActivateModel,CourseActivateModelAdmin)